/*
 *	main-view view
 *  -----------------------------------------------------------------------------------------------------------
 */

site.view('main-login-view', {
	
	onLoad: function(settings) {
		this.startAll(settings);
	},
	
	onUnload: function() {
		this.stopAll();
	}

})

/*
 *	invitation-form
 *  -----------------------------------------------------------------------------------------------------------
 */

.module('invitation-form', function(context) {
	var util = context.util,
		require = context.require,
		ajaxSubmitForm = require('ajaxSubmitForm'),
  		notify = require('notify'),
  		invitations_amount = context.query('#invitations_amount');

	return {
		init: function() {
			ajaxSubmitForm.init('#invitation_form',{


				success: function(data) {
					notify.create("create", {
						title: data.message,
						text: data.description
					});  

					invitations_amount.html(function(index, old_content) {
						return ++old_content;
					});

					this[0].reset();
				},

				error: function(data) {
					var err_msg = '';

					util.eachRecursive(data.errors, function(key, val) {
						err_msg += err_msg === '' ? val : '<br/>' + val;
					})

					notify.create('create','error-template', {
						title: data.message,
						text: err_msg
					});
				}
			});
		}
	}
})

/*
 *	notification-scroll
 *  -----------------------------------------------------------------------------------------------------------
 */

.module('notification-scroll', function(context) {
	var contact_list = context.query('#mini_notification_list > ul'),
		slim_scroll = context.require('slimScroll');

	return {
		init: function() {
			if(contact_list.children('li').size() > 5) {
				slim_scroll.init(contact_list, { 
					height: '235px', 
					right: '0px', 
					'z-index': 1 
				})	
			}
			
		}
	}
})